import React, { Component } from 'react'
import {Route, Switch, Redirect} from 'react-router-dom'
// 路由组件 不传props 收到的是{history、location、match}
import About from '../../pages/ReactRouter/About'
import Home from '../../pages/ReactRouter/Home'
// 一般组件 不传props 收到的是{}
import Header from '../../components/ReactRouter/Header'
import MyNavLink from '../../components/ReactRouter/MyNavLink'

export default class index extends Component {
  render() {
    return (
      <div>
        <div>
          <div className="row">
            <div className="col-xs-offset-2 col-xs-8">
              <Header/>
            </div>
          </div>
          <div className="row">
            <div className="col-xs-2 col-xs-offset-2">
              <div className="list-group">
                {/* <a className="list-group-item active" href="./about.html">About</a>
                <a className="list-group-item" href="./home.html">Home</a> */}
                {/* Link无法实现高亮效果 使用NavLink 自动给当前路由组件追加一个active的类名 可以传递一个activeClassName指定自定义类名 */}
                  <MyNavLink className="list-group-item"  to="/home">Home</MyNavLink>
                  <MyNavLink className="list-group-item" to="/about">About</MyNavLink>
              </div>
            </div>
            <div className="col-xs-6">
              <div className="panel">
                <div className="panel-body">
                  {/* 注册路由 */}
                  <Switch>
                    <Route path="/home" component={Home}/>
                    <Route path="/about" component={About}/>
                    {/* 谁都匹配不上的时候使用Redirect指向的路径 */}
                    <Redirect to="/home"/>
                    </Switch>
                  {/* <h3>我是???的内容</h3> */}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    )
  }
}
